﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class D07_Navgation : MonoBehaviour
{
    private NavMeshAgent nav;
    private Camera cam;

    private void Start()
    {
        nav = GetComponent<NavMeshAgent>();
        cam = Camera.main;
    }

    private void Update()
    {
        if (Input.GetMouseButtonDown(1))//如果点击鼠标右键
        {
            RaycastHit hitInfo;
            if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hitInfo))
            {
                nav.SetDestination(hitInfo.point);//设置寻路组件的目标点
            }
        }
    }
}